<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="com.ejoysoft.common.Constants,com.ejoysoft.util.ParamUtil,com.ejoysoft.wlanyz.business.Task,com.ejoysoft.wlanyz.business.Ap,com.ejoysoft.common.*,com.ejoysoft.wlanyz.business.Ac,java.io.File,java.util.ArrayList,java.util.Vector,java.io.FileNotFoundException"%>
<%@ include file="../include/jsp/head.jsp"%>
<%@ page import="java.util.List" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%
	try {
		Task obj = new Task(globa, false);

		String strUrl = "task_list.jsp";
		String strUrl1 = "task_add.jsp";
		if (action.equals(Constants.DELETE_STR)) {
			String[] aryStrId = ParamUtil.getStrArray(request, "strTaskId");
			for (int i = 0; i < aryStrId.length; i++) {
				obj.delete("where strTaskId ='" + aryStrId[i] + "'");
			}
			globa.dispatch(true, strUrl);
		} else if (action.equals(Constants.ADD_STR)) {
		    
		    String strTaskMan = ParamUtil.getString(request, "strTaskMan","");
			String strTaskPhone = ParamUtil.getString(request, "strTaskPhone","");
			String strTaskName = ParamUtil.getString(request, "strTaskName","");
			String strTaskType = ParamUtil.getString(request, "strTaskType","");
			String strNetType = ParamUtil.getString(request, "strNetType","");
			String dtStartTime = ParamUtil.getString(request, "dtStartTime","");
			String dtEndTime = ParamUtil.getString(request, "dtEndTime","");
			String strTaskDes = ParamUtil.getString(request, "strTaskDes","");
			String strPingAddr = ParamUtil.getString(request, "strPingAddr","");
			String strHttpSite = ParamUtil.getString(request, "strHttpSite","");
			String strFtpAddress = ParamUtil.getString(request, "strFtpAddress","");
			String strTestCount = ParamUtil.getString(request, "strTestCount");
			String strRemark = ParamUtil.getString(request, "strRemark","");
			String strHotpotName = ParamUtil.getString(request, "strHotPotName","");
			String intIssued = ParamUtil.getString(request, "intIssued");
			String strApIds="" ;
			if (intIssued!=null){
	  			Ap obj2=new Ap(globa,false);
	            String tWhere=" where strHotSpot='"+strHotpotName+"'"; 
	            Vector<Ap> vctObj=obj2.list(tWhere,0,0);
	            String [] apids = new String [vctObj.size()];
	            for (int i = 0; i < vctObj.size(); i++) {
	               Ap obj3=vctObj.get(i);
	               apids[i] = obj3.getDevice_Id();
	             }
	            List<String> random = obj.randommm(apids.length);
	            for(int i=0;i< random.size();i++)
		            {
		            strApIds+= apids[Integer.parseInt(random.get(i))]+",";
		            }
				strApIds=strApIds.substring(0,strApIds.length()-1);
			}
			
			else 
			{
			intIssued="0";
			strApIds ="";
			}
			System.out.println("44444444444444:::::"+strApIds);
			globa.dispatch(obj.add(strTaskMan,strTaskPhone,strTaskName,strTaskType,strNetType,dtStartTime,dtEndTime,strTaskDes,strPingAddr,strHttpSite,strFtpAddress,strTestCount,strRemark,strHotpotName,intIssued,strApIds), strUrl);
		}
		else if(action.equals(Constants.ADD_STR1)){
		    String intIssued ="1";
		   String strTaskId = ParamUtil.getString(request, "strTaskId");
		    String[] arydeviceId = ParamUtil.getStrArray(request, "device_Id");
		    String strApIds="";
		   int flag=1;
           for(int i = 0; i < arydeviceId.length; i++){
                if(flag==1){
               	strApIds=strApIds+arydeviceId[i];
                		flag=0;
                	}
                	else{
                		strApIds=strApIds+','+arydeviceId[i];
                	}
                }
                globa.dispatch(obj.add1(strTaskId,strApIds,intIssued),strUrl);
         }
			
		
		else if(action.equals(Constants.UPDATE_STR)){
            String  strTaskId=ParamUtil.getString(request,"strTaskId","");
            String strTaskMan = ParamUtil.getString(request, "strTaskMan", "");
			String strTaskPhone = ParamUtil.getString(request, "strTaskPhone", "");
			String strTaskName = ParamUtil.getString(request, "strTaskName", "");
			String strTaskType = ParamUtil.getString(request, "strTaskType","");
			String strNetType = ParamUtil.getString(request, "strNetType","");
			String dtStartTime = ParamUtil.getString(request, "dtStartTime","");
			String dtEndTime = ParamUtil.getString(request, "dtEndTime","");
			String strTaskDes = ParamUtil.getString(request, "strTaskDes","");
			String strPingAddr = ParamUtil.getString(request, "strPingAddr","");
			String strHttpSite = ParamUtil.getString(request, "strHttpSite","");
			String strFtpAddress = ParamUtil.getString(request, "strFtpAddress","");
			String strTestCount = ParamUtil.getString(request, "strTestCount");
			String strRemark = ParamUtil.getString(request, "strRemark","");
			String strHotPotName = ParamUtil.getString(request, "strHotPotName","");
			String intIssued = ParamUtil.getString(request, "intIssued");
			String strApIds ="1,2,3,4,5";
			
			//String strApIds = ParamUtil.getString(request, "strApIds");
			//System.out.println("yyyyyyyyyyyy"+strNetType);
                 globa.dispatch(obj.update(strTaskId,strTaskMan,strTaskPhone,strTaskName,strTaskType,strNetType,dtStartTime,dtEndTime,strTaskDes,strPingAddr,strHttpSite,strFtpAddress,strTestCount,strRemark,strHotPotName,intIssued,strApIds),strUrl);
      }

		
		globa.closeCon();
	}

	catch (Exception e) {
		e.printStackTrace();
	}
%>